import { signIn,resetPwd } from '@/api/user';

const state = {
    registerInfo: {
    },
    emailInfo: {
    },
    code:''
};

const mutations = {
    SET_REGISTER_INFO: (state, registerInfo) => {
        state.registerInfo = registerInfo;
    },
    SET_EMAIL_INFO: (state, emailInfo) => {
        state.emailInfo = emailInfo;
    },
    SET_CODE: (state, code) => {
        state.code = code;
    }
};
const actions = {
    async setReGisterInfo({ commit }, data) {
        commit('SET_REGISTER_INFO', data);
    },
    async setEmailInfo({ commit }, data) {
        commit('SET_EMAIL_INFO', data);
    },
    async setCode({ commit }, data) {
        commit('SET_CODE', data);
    },
    async signIn({ state }, data) {
        let param = {
            ...state.registerInfo,
            phoneNumber: data,
            ...state.emailInfo
        }
        return new Promise((resolve) => {
            signIn(param).then(res => {
                resolve(res)
            })
        });
   
    },
    async resetPwd({ state }, data) {
        let param = {
            code:state.code,
           ...data
         
        }
        return new Promise((resolve) => {
            resetPwd(param).then(res => {
                resolve(res)
            })
        });
   
    },


};
export default {
    namespaced: true,
    state,
    mutations,
    actions
};
